package jdbc;

import util.DBUtil;

import java.sql.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class ConnectionMeta {
    public static void main(String[] args) {
        Connection con= DBUtil.getConnection();
        try {
            DatabaseMetaData metaData = con.getMetaData();
            System.out.println(metaData.getDatabaseProductName()+"."+metaData.getDatabaseProductVersion());
            System.out.println(metaData.getMaxColumnsInIndex()+"索引中的最多列数！");
            PreparedStatement ps=con.prepareStatement("select * from s_student");
            ResultSet rs=ps.executeQuery();
            //
            ResultSetMetaData rm = rs.getMetaData();
            System.out.println("表："+rm.getTableName(1));
            for(int i=1;i<=rm.getColumnCount();i++){
                System.out.println("列名："+rm.getColumnLabel(i)+"，列类型："+rm.getColumnTypeName(i)+",对应的java类型："+rm.getColumnClassName(i));
            }
            DBUtil.close(con);
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
